<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工艺路线编号" prop="routeCode">
        <el-input
          v-model="queryParams.routeCode"
          placeholder="请输入工艺路线编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工艺路线名称" prop="routeName">
        <el-input
          v-model="queryParams.routeName"
          placeholder="请输入工艺路线名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否启用" prop="enableFlag">
        <el-select
          v-model="queryParams.enableFlag"
          placeholder="请选择是否启用"
          clearable
        >
          <el-option
            v-for="dict in dict.type.enable_flag"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="Search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:route:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:route:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:route:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:route:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="routeList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工艺路线编号" align="center" prop="routeCode">
        <template #default="{ row }">
          <el-button type="text" @click="handleView(row)">
            {{ row.routeCode }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="工艺路线名称" align="center" prop="routeName" />
      <el-table-column label="工艺路线说明" align="center" prop="routeDesc" />
      <el-table-column label="是否启用" align="center" prop="enableFlag">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.enable_flag"
            :value="scope.row.enableFlag"
          />
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:route:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="Delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:route:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工艺路线对话框 -->
    <el-dialog :title="title" v-model="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="工艺路线名称" prop="routeName">
          <el-input v-model="form.routeName" placeholder="请输入工艺路线名称" />
        </el-form-item>
        <el-form-item label="工艺路线说明" prop="routeDesc">
          <el-input
            v-model="form.routeDesc"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="是否启用" prop="enableFlag">
          <el-radio-group v-model="form.enableFlag">
            <el-radio
              v-for="dict in dict.type.enable_flag"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-divider content-position="center">工艺组成信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="Plus"
              size="mini"
              @click="handleAddProRouteProcess"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="Delete"
              size="mini"
              @click="handleDeleteProRouteProcess"
              >删除</el-button
            >
          </el-col>
        </el-row>
        <el-table
          :data="proRouteProcessList"
          :row-class-name="rowProRouteProcessIndex"
          @selection-change="handleProRouteProcessSelectionChange"
          ref="proRouteProcess"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          />
          <el-table-column label="工序编码" prop="processCode" width="150">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.processCode"
                placeholder="请选择工序"
                filterable
                clearable
                @change="handleProcessSelect(scope.row)"
              >
                <el-option
                  v-for="item in processOptions"
                  :key="item.processCode"
                  :label="item.processCode"
                  :value="item.processCode"
                />
              </el-select>
            </template>
          </el-table-column>

          <el-table-column label="工序名称" prop="processName" width="150">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.processName"
                placeholder="请选择工序"
                filterable
                clearable
                @change="handleProcessSelectByName(scope.row)"
              >
                <el-option
                  v-for="item in processOptions"
                  :key="item.processName"
                  :label="item.processName"
                  :value="item.processName"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="序号" prop="orderNum" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.orderNum" placeholder="请输入序号" />
            </template>
          </el-table-column>
          <el-table-column
            label="下一道工序"
            prop="nextProcessName"
            width="150"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.nextProcessName"
                placeholder="请输入下一道工序"
              />
            </template>
          </el-table-column>
          <el-table-column label="与下一道工序关系" prop="linkType" width="150">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.linkType"
                placeholder="请选择与下一道工序关系"
              >
                <el-option
                  v-for="dict in dict.type.link_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="准备时间" prop="defaultPreTime" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.defaultPreTime"
                placeholder="请输入准备时间"
              />
            </template>
          </el-table-column>
          <el-table-column label="等待时间" prop="defaultSufTime" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.defaultSufTime"
                placeholder="请输入等待时间"
              />
            </template>
          </el-table-column>
          <el-table-column label="甘特图显示颜色" prop="colorCode" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.colorCode"
                placeholder="请输入甘特图显示颜色"
              />
            </template>
          </el-table-column>
          <el-table-column label="关键工序" prop="keyFlag" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.keyFlag"
                placeholder="请输入关键工序"
              />
            </template>
          </el-table-column>
          <el-table-column label="质检确认" prop="isCheck" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.isCheck"
                placeholder="请输入质检确认"
              />
            </template>
          </el-table-column>
        </el-table>
        <el-divider content-position="center">关联产品信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="Plus"
              size="mini"
              @click="handleAddProRouteProduct"
              >添加产品</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="Delete"
              size="mini"
              @click="handleDeleteProRouteProduct"
              >删除产品</el-button
            >
          </el-col>
        </el-row>
        <el-table
          :data="proRouteProductList"
          :row-class-name="rowProRouteProductIndex"
          @selection-change="handleProRouteProductSelectionChange"
          ref="proRouteProduct"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          />
          <el-table-column label="产品物料编码" prop="itemCode" width="200">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.itemCode"
                placeholder="请选择物料"
                filterable
                clearable
                @change="handleItemSelect(scope.row)"
              >
                <el-option
                  v-for="item in itemOptions"
                  :key="item.itemCode"
                  :label="item.itemCode"
                  :value="item.itemCode"
                />
              </el-select>
            </template>
          </el-table-column>

          <el-table-column label="产品物料名称" prop="itemName" width="200">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.itemName"
                placeholder="请选择物料"
                filterable
                clearable
                @change="handleItemSelectByName(scope.row)"
              >
                <el-option
                  v-for="item in itemOptions"
                  :key="item.itemName"
                  :label="item.itemName"
                  :value="item.itemName"
                />
              </el-select>
            </template>
          </el-table-column>

          <el-table-column label="规格型号" prop="specification" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.specification" readonly />
            </template>
          </el-table-column>

          <el-table-column label="单位" prop="unitOfMeasure" width="150">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.unitOfMeasure"
                placeholder="请选择单位"
                filterable
                clearable
              >
                <el-option
                  v-for="item in measureOptions"
                  :key="item.measureCode"
                  :label="item.measureName"
                  :value="item.measureCode"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="生产数量" prop="quantity" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.quantity"
                placeholder="请输入生产数量"
              />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 查看工艺流程 -->
    <el-dialog
      title="查看工艺流程"
      v-model="show"
      width="900px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="工艺路线编号" prop="routeCode">
          <el-input
            v-model="form.routeCode"
            placeholder="请输入工艺路线编号"
            readonly
          />
        </el-form-item>
        <el-form-item label="工艺路线名称" prop="routeName">
          <el-input
            v-model="form.routeName"
            placeholder="请输入工艺路线名称"
            readonly
          />
        </el-form-item>
        <el-form-item label="工艺路线说明" prop="routeDesc">
          <el-input
            v-model="form.routeDesc"
            type="textarea"
            placeholder="请输入内容"
            readonly
          />
        </el-form-item>
        <el-form-item label="是否启用" prop="enableFlag">
          <el-radio-group v-model="form.enableFlag">
            <el-radio
              v-for="dict in dict.type.enable_flag"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
            readonly
          />
        </el-form-item>
        <el-divider content-position="center">工艺组成信息</el-divider>
        <el-table
          :data="proRouteProcessList"
          :row-class-name="rowProRouteProcessIndex"
          @selection-change="handleProRouteProcessSelectionChange"
          ref="proRouteProcess"
        >
          <el-table-column label="序号" prop="orderNum" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.orderNum"
                placeholder="请输入序号"
                readonly
              />
            </template>
          </el-table-column>
          <el-table-column label="工序编码" prop="processCode" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.processCode"
                placeholder="请输入工序编码"
                readonly
              />
            </template>
          </el-table-column>
          <el-table-column label="工序名称" prop="processName" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.processName"
                placeholder="请输入工序名称"
                readonly
              />
            </template>
          </el-table-column>
          <el-table-column
            label="下一道工序"
            prop="nextProcessName"
            width="150"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.nextProcessName"
                placeholder="请输入下一道工序"
                readonly
              />
            </template>
          </el-table-column>
          <el-table-column label="与下一道工序关系" prop="linkType" width="150">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.linkType"
                placeholder="请选择与下一道工序关系"
                disabled
              >
                <el-option
                  v-for="dict in dict.type.link_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="准备时间" prop="defaultPreTime" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.defaultPreTime"
                placeholder="请输入准备时间"
                readonly
              />
            </template>
          </el-table-column>
          <el-table-column label="等待时间" prop="defaultSufTime" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.defaultSufTime"
                placeholder="请输入等待时间"
                readonly
              />
            </template>
          </el-table-column>
          <el-table-column label="甘特图显示颜色" prop="colorCode" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.colorCode"
                placeholder="请输入甘特图显示颜色"
                readonly
              />
            </template>
          </el-table-column>
          <el-table-column label="关键工序" prop="keyFlag" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.keyFlag"
                placeholder="请输入关键工序"
                readonly
              />
            </template>
          </el-table-column>
          <el-table-column label="质检确认" prop="isCheck" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.isCheck"
                placeholder="请输入质检确认"
                readonly
              />
            </template>
          </el-table-column>
        </el-table>
        <el-divider content-position="center">关联产品信息</el-divider>
        <el-table :data="proRouteProductList" border>
          <el-table-column label="产品物料编码" prop="itemCode" width="200">
            <template slot-scope="scope">
              <el-input v-model="scope.row.itemCode" readonly />
            </template>
          </el-table-column>
          <el-table-column label="产品物料名称" prop="itemName" width="200">
            <template slot-scope="scope">
              <el-input v-model="scope.row.itemName" readonly />
            </template>
          </el-table-column>
          <el-table-column label="规格型号" prop="specification" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.specification" readonly />
            </template>
          </el-table-column>
          <el-table-column label="单位" prop="unitOfMeasure" width="150">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.unitOfMeasure"
                placeholder="请选择单位"
                filterable
                clearable
                disabled
              >
                <el-option
                  v-for="item in measureOptions"
                  :key="item.measureCode"
                  :label="item.measureName"
                  :value="item.measureCode"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="生产数量" prop="quantity" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.quantity" readonly />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="Route">
import { ref, reactive, onMounted } from 'vue'
import { useDict } from '@/utils/dict'
import { listRoute, getRoute, delRoute, addRoute, updateRoute } from "@/api/system/route"
import { listProcess } from "@/api/system/process"
import { listItem } from "@/api/system/item"
import { listMeasure } from "@/api/system/measure"

// 使用组合式API的方式获取字典数据
const { dict } = useDict('enable_flag', 'link_type')

// 查询参数
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  routeCode: '',
  routeName: '',
  enableFlag: undefined
})

// 表格数据
const routeList = ref([])
const loading = ref(false)
const total = ref(0)
const show = ref(false)
const open = ref(false)
const title = ref('')
const single = ref(true)
const multiple = ref(true)
const showSearch = ref(true)
const processOptions = ref([])
const itemOptions = ref([])
const measureOptions = ref([])
const proRouteProcessList = ref([])
const proRouteProductList = ref([])

// 表单参数
const form = reactive({
  routeId: undefined,
  routeCode: '',
  routeName: '',
  routeDesc: '',
  enableFlag: 'Y',
  remark: '',
  routeDetailList: []
})

/** 查询工艺路线列表 */
const getList = async () => {
  try {
    loading.value = true
    const response = await listRoute(queryParams)
    routeList.value = response.rows
    total.value = response.total
  } catch (error) {
    console.error('获取数据失败:', error)
  } finally {
    loading.value = false
  }
}

// 在组件挂载时获取数据
onMounted(() => {
  getList()
  // 获取工序列表
  listProcess().then(response => {
    processOptions.value = response.rows
  })
  // 获取物料列表
  listItem().then(response => {
    itemOptions.value = response.rows
  })
  // 获取计量单位列表
  listMeasure().then(response => {
    measureOptions.value = response.rows
  })
})

const rules = reactive({
  routeName: [
    { required: true, message: "工艺路线名称不能为空", trigger: "blur" }
  ],
  enableFlag: [
    { required: true, message: "是否启用不能为空", trigger: "change" }
  ]
});

/** 取消按钮 */
function cancel() {
  open.value = false;  
  show.value = false;
  reset();
}

/** 表单重置 */
function reset() {
  Object.assign(form, {
    routeId: undefined,
    routeCode: undefined,
    routeName: undefined,
    routeDesc: undefined,
    enableFlag: "Y",
    remark: undefined,
    routeDetailList: []
  });
  proxy.resetForm("form");
}

/** 查询明细按钮操作 */
function handleView(row) {
  reset();
  Object.assign(form, {
    routeId: row.routeId,
    routeCode: row.routeCode,
    routeName: row.routeName,
    routeDesc: row.routeDesc,
    enableFlag: row.enableFlag,
    remark: row.remark  
  });
  const routeId = row.routeId;
  getRoute(routeId).then((response) => {
    Object.assign(form, response.data);
    proRouteProcessList.value = response.data.proRouteProcessList;
    proRouteProductList.value = response.data.proRouteProductList;
    show.value = true;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryForm");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.routeId);
  single.value = selection.length !== 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加工艺路线";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const routeId = row.routeId || ids.value;
  getRoute(routeId).then((response) => {
    Object.assign(form, response.data);
    proRouteProcessList.value = response.data.proRouteProcessList;
    proRouteProductList.value = response.data.proRouteProductList;
    open.value = true;
    title.value = "修改工艺路线";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["form"].validate((valid) => {
    if (valid) {
      form.proRouteProcessList = proRouteProcessList.value;
      form.proRouteProductList = proRouteProductList.value;
      if (form.routeId != null) {
        updateRoute(form).then(() => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addRoute(form).then(() => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const routeIds = row.routeId || ids.value;
  proxy.$modal
    .confirm('是否确认删除工艺路线编号为"' + routeIds + '"的数据项？')
    .then(function () {
      return delRoute(routeIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}

/** 工艺组成序号 */
function rowProRouteProcessIndex({ row, rowIndex }) {
  row.index = rowIndex + 1;
}

/** 工艺组成添加按钮操作 */
function handleAddProRouteProcess() {
  let obj = {
    processCode: "",
    processName: "",
    orderNum: "",
    nextProcessName: "",
    linkType: "",
    defaultPreTime: "",
    defaultSufTime: "",
    colorCode: "",
    keyFlag: "",
    isCheck: ""
  };
  proRouteProcessList.value.push(obj);
}

/** 工艺组成删除按钮操作 */
function handleDeleteProRouteProcess() {
  if (checkedProRouteProcess.value.length == 0) {
    proxy.$modal.msgError("请先选择要删除的工艺组成数据");
  } else {
    proRouteProcessList.value = proRouteProcessList.value.filter(function (item) {
      return checkedProRouteProcess.value.indexOf(item.index) == -1;
    });
  }
}

/** 复选框选中数据 */
function handleProRouteProcessSelectionChange(selection) {
  checkedProRouteProcess.value = selection.map((item) => item.index);
}

/** 工序选择处理 */
function handleProcessSelect(row) {
  const selected = processOptions.value.find(
    (p) => p.processCode === row.processCode
  );
  if (selected) {
    row.processName = selected.processName;
    row.processId = selected.processId;
  }
}

/** 根据工序名称选择处理 */
function handleProcessSelectByName(row) {
  const selected = processOptions.value.find(
    (p) => p.processName === row.processName
  );
  if (selected) {
    row.processCode = selected.processCode;
    row.processId = selected.processId;
  }
}

/** 添加产品行 */
function handleAddProRouteProduct() {
  let obj = {
    itemCode: "",
    itemName: "",
    specification: "",
    unitOfMeasure: "",
    quantity: ""
  };
  proRouteProductList.value.push(obj);
}

/** 删除产品行 */
function handleDeleteProRouteProduct() {
  if (checkedProRouteProduct.value.length === 0) {
    proxy.$modal.msgError("请先选择要删除的产品数据");
  } else {
    proRouteProductList.value = proRouteProductList.value.filter(
      (item, index) => !checkedProRouteProduct.value.includes(index + 1)
    );
  }
}

/** 产品复选框选中 */
function handleProRouteProductSelectionChange(selection) {
  checkedProRouteProduct.value = selection.map((item) => item.index);
}

/** 产品行序号生成 */
function rowProRouteProductIndex({ row, rowIndex }) {
  row.index = rowIndex + 1;
}

/** 物料选择处理 */
function handleItemSelect(row) {
  const selected = itemOptions.value.find(
    (p) => p.itemCode === row.itemCode
  );
  if (selected) {
    row.itemName = selected.itemName;
    row.specification = selected.specification;
    row.unitOfMeasure = selected.unitOfMeasure;
  }
}

/** 通过名称选择处理 */
function handleItemSelectByName(row) {
  const selected = itemOptions.value.find(
    (p) => p.itemName === row.itemName
  );
  if (selected) {
    row.itemCode = selected.itemCode;
    row.specification = selected.specification;
    row.unitOfMeasure = selected.unitOfMeasure;
  }
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "system/route/export",
    {
      ...queryParams
    },
    `route_${new Date().getTime()}.xlsx`
  );
}

/** 初始化 */
onMounted(() => {
  getList();
  listProcess().then(response => {
    processOptions.value = response.rows;
  });
  listItem().then(response => {
    itemOptions.value = response.rows;
  });
  listMeasure().then(response => {
    measureOptions.value = response.rows;
  });
});
</script>
<style scoped>
.el-select {
  width: 100%;
}
</style>